package org.example.ffmmx.bmapandroid;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.SeekBar;
import com.baidu.mapapi.map.*;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.utils.DistanceUtil;


public class DrawCircleDemo extends Activity {
    TextureMapView bMapView;
    SeekBar seekBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.draw_circle);
        bMapView = (TextureMapView) findViewById(R.id.baiduTextureView);
        seekBar = (SeekBar) findViewById(R.id.seekBar);

        final BaiduMap map = bMapView.getMap();
        final LatLng point = new LatLng(39.963175, 116.400244);
        final LatLng point2=new LatLng(39.963075, 116.400144);
        final LatLng point3=new LatLng(39.963275, 116.400344);
        final CircleOptions circle = new CircleOptions().fillColor(Color.BLUE).center(point).radius(100);
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                map.clear();
                CircleOptions circle = new CircleOptions().fillColor(Color.BLUE).center(point).radius(progress);
                map.addOverlay(circle);
                BitmapDescriptor icon_marker2=BitmapDescriptorFactory.fromResource(R.drawable.icon_marka);
                OverlayOptions marker2= new MarkerOptions().icon(icon_marker2).position(point2);
                map.addOverlay(marker2);
                BitmapDescriptor icon_marker3=BitmapDescriptorFactory.fromResource(R.drawable.icon_markb);
                OverlayOptions marker3=new MarkerOptions().icon(icon_marker3).position(point3);
                map.addOverlay(marker3);
                double z=0;

                z= DistanceUtil.getDistance(point,point2);
                System.out.println("z = "+z+" , progress = "+progress);
                if(progress-z > 0)
                    System.out.println("user point 2 in circle");
                else if(progress - z ==0)
                    System.out.println("user point 2 at circle");

                z= DistanceUtil.getDistance(point,point3);
                if(progress-z > 0)
                    System.out.println("user point 3 in circle");
                else if(progress - z ==0)
                    System.out.println("user point 3 at circle");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
        BitmapDescriptor icon_marker2=BitmapDescriptorFactory.fromResource(R.drawable.icon_marka);
        OverlayOptions marker2= new MarkerOptions().icon(icon_marker2).position(point2);
        map.addOverlay(marker2);
        BitmapDescriptor icon_marker3=BitmapDescriptorFactory.fromResource(R.drawable.icon_markb);
        OverlayOptions marker3=new MarkerOptions().icon(icon_marker3).position(point3);
        map.addOverlay(marker3);
        map.addOverlay(circle);
    }

    @Override
    protected void onResume() {
        super.onResume();
        bMapView.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        bMapView.onDestroy();
    }

    @Override
    protected void onPause() {
        super.onPause();
        bMapView.onPause();
    }

}
